package 剑指Offer._1120;

/**
 * @author yzh
 * @version 1.0
 * @date 2021/7/20 20:21
 * 数值的整数次方
 * 算法：快速幂
 */
public class _16 {
    public static void main(String[] args) {
        System.out.println(new _16().myPow(2.00000, -2147483648));
    }

    public double myPow(double x, int n) {
        if (n == 0) return 1;
        long N = n;
        if (N < 0) {
            x = 1 / x;
            N = -N;
        }
        double ans = 1;
        while (N > 0) {
            if ((N & 1) == 1) ans *= x;
            x *= x;
            N /= 2;
        }
        return ans;
    }

}
